/**
 * 扑克类叫分
 */
var _ = require('./../../FrameWork/we_underscore');
var TimeOutCtr = require('./../../FrameWork/Component/TimeOutCtr');
var EnumPkRoom = require('./../Enum/EnumPkRoom');
var ClientDelegate = require('./../../FrameWork/Delegate/ClientDelegate');
var ClientPkDelegateType = require('./../Delegate/ClientPkDelegateType');
var UtilGameObject = require('./../../FrameWork/Utils/UtilGameObject');
module.exports = cc.Class({
    extends: ClientDelegate,
    properties: {
        timeOutCtr: {
            default: null,
            type: TimeOutCtr,
            displayName: '倒计时组件'
        },
        prefabLb: {
            default: null,
            type: cc.Prefab,
            displayName: '文字预设'
        },
        nodeNoCall: {
            default: null,
            type: cc.Node,
            displayName: '不叫'
        },
        nodeScore1: {
            default: null,
            type: cc.Node,
            displayName: '1分'
        },
        nodeScore2: {
            default: null,
            type: cc.Node,
            displayName: '2分'
        },
        nodeScore3: {
            default: null,
            type: cc.Node,
            displayName: '3分'
        }
    },
    onLoad() {
        this._super();
        this.addListerDelegate(ClientPkDelegateType.Clinet_selfCallScoring, this.doActive.bind(this));
        var posList = [{
            pos: this.nodeNoCall,
            world: '不 叫'
        }, {
            pos: this.nodeScore1,
            world: '1 分'
        }, {
            pos: this.nodeScore2,
            world: '2 分'
        }, {
            pos: this.nodeScore3,
            world: '3 分'
        }];
        _.each(posList, function(_info) {
            var lbCtr = UtilGameObject.getCtrByPrefabs(this.prefabLb, _info.pos);
            lbCtr.setFontSize(43);
            lbCtr.setPositionY(5);
            lbCtr.setText(_info.world);
            lbCtr.setOutlineWidth2(5);
        }.bind(this));


        this.iniTest();
        this.resetNet();

    },
    resetNet() {
        var isCallScoring = (window.g_room && EnumPkRoom.CALLSCORING == window.g_room.getRoomState());
        this.doActive(isCallScoring);
    },
    doActive(_isCallScoring) {
        this.setActive(_isCallScoring);
        if (_isCallScoring) {
            this.open();
        }
    },
    /***不叫分 */
    eveNoCall() {
        this.doActive(false);
        if (!!window.g_room) {
            window.g_room.refreshCallScore({
                seatIdx: window.g_room.getSelfSeatIdx(),
                score: 0
            });
        }
    },
    /**叫的分数 */
    eveCallScore(event, _jData) {
        this.doActive(false);
        if (!!window.g_room) {
            window.g_room.refreshCallScore({
                seatIdx: window.g_room.getSelfSeatIdx(),
                score: parseInt(_jData)
            });
        }
    },
    showBtnLayer(b) {
        // b = null == b ? true : b;
        // this.nodeBtnsLayer.active = b;
    },
    /***开启倒计时叫分
     * _timeOut:倒计时时间单位（秒）默认不填10秒
     */
    open(_timeOut) {
        _timeOut = null == _timeOut ? 20 : _timeOut;
        this.timeOutCtr.startCountDown(_timeOut, this.eveNoCall.bind(this));
    },
    iniTest() {
        // UtilGameObject.createDemoBtn([
        //     ['头像', function() {
        //             this.showHeadAll();
        //         }.bind(this)

        //     ],
        // ]);
        // this.showHeadAll();
    }
});